﻿using Ledict.ConditionExtract.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace Ledict.ConditionExtract.Frm
{
    public partial class NodeTreeCondition : BaseForm
    {
        public string  CCName { get; set; }
        public NodeTreeCondition()
        {
            InitializeComponent();
            
        }

        public NodeTreeCondition(string TxbConditionName1, string TxbConditionContent1, string TxbConditionExplain1,string ccName)
        {
            InitializeComponent();
            colFileter1.CCName = ccName;
            TxbConditionName = TxbConditionName1;
            TxbConditionContent = TxbConditionContent1;
            TxbConditionExplain = TxbConditionExplain1;
        }

        /// <summary>
        /// 配置名称
        /// </summary>
        public string TxbConditionName { get; set; }

        /// <summary>
        /// 配置条件
        /// </summary>
        public string TxbConditionContent { get; set; }

        /// <summary>
        /// 配置说明
        /// </summary>
        public string TxbConditionExplain { get; set; }

        private void MoveState_Load(object sender, EventArgs e)
        {
            this.txbConditionName.Text = TxbConditionName;
            colFileter1.SetFileter(TxbConditionContent);           
            //  this.txbConditionContent.Text = TxbConditionContent;
            this.txbConditionExplain.Text = TxbConditionExplain;
        }

        private void MoveState_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        /// <summary>
        /// 确定按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConfig_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txbConditionName.Text))
            {
                MessageBox.Show("名称不能为空！");
                txbConditionName.Focus();
                return;
            }
            if (string.IsNullOrWhiteSpace(colFileter1.GetFileter()))
            {
                MessageBox.Show("条件不能为空！");
                //txbConditionContent.Focus();
                return;
            }
            if (string.IsNullOrWhiteSpace(txbConditionExplain.Text))
            {
                MessageBox.Show("说明不能为空！");
                txbConditionExplain.Focus();
                return;
            }
            try
            {
                string XMLText = colFileter1.GetFileter().Replace("\r", "").Replace("\t", "").Replace("\n", "").Replace("-", "").Replace("、", @"");
                XmlDocument document = new XmlDocument();
                document.LoadXml(XMLText);
            }
            catch (Exception ex)
            {
                MessageBox.Show("条件XML格式不正确！" + ex.Message);
               // txbConditionContent.Focus();
                return;
            }
            TxbConditionName = txbConditionName.Text.Trim();
            TxbConditionContent = colFileter1.GetFileter();
            TxbConditionExplain = txbConditionExplain.Text.Trim();
            this.Close();
            DialogResult = DialogResult.OK;
        }
    }
}
